#include <cstdio>
#include <algorithm>

using namespace std;

typedef unsigned int ui;
const int maxn=300000;

namespace my {
//Tree
    int n, son[maxn+1], bro[maxn+1], fa[maxn+1], dfn[maxn+1], size[maxn+1];

    void addSide(int f, int s) {
        fa[s] = f;
        bro[s] = son[f];
        son[f] = s;
    }

    void build(int o) {
        size[o] = 1;
        dfn[o] = ++dfn[0];
        for (int i=son[o]; i; i=bro[i]) {
            build(i);
            size[o] += size[i];
        }
    }

//SegmentTree
    ui sum[4*maxn+1], tag[4*maxn+1][4], cnt[4*maxn+1];

    void init(int o, int l, int r) {
        if (l!=r) {
            int mid=(l+r)/2;
            init(o*2, l, mid);
            init(o*2+1, mid+1, r);
        }
        cnt[o] = r-l+1;
    }

    void pushDown(int o, ui l, ui r) {
        sum[o] += tag[o][1]*cnt[o]+tag[o][3]*(r-l+1)+tag[o][2]*(r-l+1-cnt[o]);
        if (l!=r) {
            for (int t=o*2; t<=o*2+1; t++) {
                if (tag[t][0]) tag[t][3] += tag[o][2];
                else {
                    tag[t][1] += tag[o][1];
                    tag[t][2] += tag[o][2];
                }
                tag[t][3] += tag[o][3];
            }
        }
        tag[o][1] = tag[o][2] = tag[o][3] = 0;
    }

    void pushUp(int o, ui l, ui r) {
        sum[o] = sum[o*2] + sum[o*2+1];
        if (l==r) cnt[o] = 1;
        else {
            cnt[o] = 0;
            if (!tag[o*2][0]) cnt[o]+=cnt[o*2];
            if (!tag[o*2+1][0]) cnt[o]+=cnt[o*2+1];
        }
    }

    void addTag(int o, ui l, ui r, ui tl, ui tr, ui to, ui tv, int cond) {
        pushDown(o, l, r);
        if (to) cond-=tag[o][0];
        if (cond<0 && to==1) return;
        if (l==tl && r==tr) {
            if (to<2) tag[o][to]+=tv;
            else tag[o][2+(cond<0)]+=tv;
            pushDown(o, l, r);
        } else {
            ui mid=(l+r)/2;
            if (tl<=mid) addTag(o*2, l, mid, tl, min(tr, mid), to, tv, cond);
            else pushDown(o*2, l, mid);
            if (tr>mid) addTag(o*2+1, mid+1, r, max(tl, mid+1u), tr, to, tv, cond);
            else pushDown(o*2+1,mid+1, r);
            pushUp(o, l, r);
        }
    }

    ui getTime(int o, ui l, ui r, ui t) {
        if (t==0) return 0;
        pushDown(o, l, r);
        if (l==r) return tag[o][0];
        else {
            ui mid=(l+r)/2;
            if (t<=mid) return getTime(o*2, l, mid, t)+tag[o][0];
            else return getTime(o*2+1, mid+1, r, t)+tag[o][0];
        }
    }

    ui getSum(int o, ui l, ui r, ui tl, ui tr) {
        pushDown(o, l, r);
        if (l==tl && r==tr) return sum[o];
        else {
            ui mid=(l+r)/2, ans=0;
            if (tl<=mid) ans+=getSum(o*2, l, mid, tl, min(tr, mid));
            if (tr>mid) ans+=getSum(o*2+1, mid+1, r, max(tl, mid+1), tr);
            return ans;
        }
    }

    int main() {
        freopen("pastel.in", "r", stdin);
        freopen("pastel.out", "w", stdout);

        int m;
        scanf("%d %d", &n, &m);
        for (int i=2; i<=n; i++) {
            int temp;
            scanf("%d", &temp);
            addSide(temp, i);
        }
        build(1);

        init(1, 1, n);
        addTag(1, 1, n, 1, n, 0, 1, 0);
        for (int i=1; i<=m; i++) {
            ui opt, k, w;
            scanf("%u", &opt);
            if (opt==1) {
                scanf("%u", &k);
                printf("%u\n", getSum(1, 1, n, dfn[k], dfn[k]));
            } else if (opt==2) {
                scanf("%u %u", &k, &w);
                addTag(1, 1, n, dfn[k], dfn[k]+size[k]-1, 1, w, getTime(1, 1, n, dfn[k]));
            } else if (opt==3) {
                scanf("%u", &k);
                printf("%u\n", getSum(1, 1, n, dfn[k], dfn[k]+size[k]-1));
            } else if (opt==4) {
                scanf("%u %u", &k, &w);
                addTag(1, 1, n, dfn[k], dfn[k]+size[k]-1, 2, w, k==1 ? 0 : getTime(1, 1, n, dfn[fa[k]]));
            } else if (opt==5) {
                scanf("%u", &k);
                addTag(1, 1, n, dfn[k], dfn[k]+size[k]-1, 0, 1, 0);
            } else if (opt==6) {
                scanf("%u", &k);
                addTag(1, 1, n, dfn[k], dfn[k]+size[k]-1, 0, -1, 0);
            }
        }

        fclose(stdin);
        fclose(stdout);
        return 0;
    }
};

int main() {return my::main();}
